package com.bee.剑指offer;

/**
 * @version 1.0.0
 * @Author yong.Mr
 * @data 2021-03-13
 */
public class 旋转数组的最小数字 {

    public static int minNumberInRotateArray(int[] array) {
        if (array.length <= 0) {
            return 0;
        }
        int flag = 0;
        for (int i = 0; i < array.length - 1; i++) {
            Boolean count = Boolean.TRUE;
            for (int j = 0; j < array.length - 1 - i; j++) {
                if (array[j] > array[j + 1]) {
                    flag = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = flag;
                    count = Boolean.FALSE;
                }
            }
            if (count) {
                break;
            }
        }
        return array.length == 0 ? 0 : array[0];
    }

    public static int minC(int[] array) {
        if (array == null || array.length <= 0) {
            return 0;
        }
        if (array.length == 1) {
            return array[0];
        }
        int min = array[0];
        for (int i = 0; i < array.length; i++) {
            min = Math.min(min, array[i]);
        }
        return min;
    }

    public static void main(String[] args) {
        int[] array = new int[]{3, 4, 5, 1, 2};
        System.out.println(minNumberInRotateArray(array));
    }
}
